package com.swsc.solarverse.cmd;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.swsc.solarverse.dao.entity.forward.ForwardStringLeDiagnoseRecordIvdataDO;
import com.swsc.solarverse.model.req.DefectQueryReqVO;
import com.swsc.solarverse.model.res.OpenApiDefectLeDetailResVO;
import com.swsc.solarverse.service.forward.IForwardStringLeDiagnoseRecordIvdataService;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author chencl
 * @Date 2025/3/3 13:52
 * @Version 1.0
 * @Description
 */
@lombok.extern.slf4j.Slf4j
@org.springframework.stereotype.Component
public class DefectLeIvdataQueryCmdExe {
    private final IForwardStringLeDiagnoseRecordIvdataService forwardStringLeDiagnoseRecordIvdataService;

    public DefectLeIvdataQueryCmdExe(IForwardStringLeDiagnoseRecordIvdataService forwardStringLeDiagnoseRecordIvdataService) {
        this.forwardStringLeDiagnoseRecordIvdataService = forwardStringLeDiagnoseRecordIvdataService;
    }

    public List<OpenApiDefectLeDetailResVO> execute(DefectQueryReqVO reqVo) {
        if (CollectionUtils.isNotEmpty(reqVo.getDefectIdIn())) {
            List<ForwardStringLeDiagnoseRecordIvdataDO> ivdataDos = forwardStringLeDiagnoseRecordIvdataService.list(Wrappers.lambdaQuery(ForwardStringLeDiagnoseRecordIvdataDO.class)
                    .in(ForwardStringLeDiagnoseRecordIvdataDO::getDefectId, reqVo.getDefectIdIn()));
            if (CollectionUtils.isNotEmpty(ivdataDos)) {
                return ivdataDos.stream().map(ivd -> {
                    return new OpenApiDefectLeDetailResVO(ivd.getTenantNo(), ivd.getOrganNo(), ivd.getDefectId(),
                            null, com.alibaba.fastjson.JSONArray.parseArray(ivd.getCurrents(), Double.class),
                            com.alibaba.fastjson.JSONArray.parseArray(ivd.getVoltages(), Double.class));
                }).collect(Collectors.toList());
            }
        }
        return null;
    }
}
